package cn.edu.scnu.springbootcinema.controller;

import cn.edu.scnu.springbootcinema.entity.Movie;
import cn.edu.scnu.springbootcinema.entity.RegionMovieCount;
import cn.edu.scnu.springbootcinema.entity.TypeAvgRating;
import cn.edu.scnu.springbootcinema.service.MovieService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/echart")
public class EchartController {

    @Resource
    private MovieService movieService;

    @GetMapping("/type_avgrating")
    public TypeAvgRating getTypeAvgRating(){
        List<Movie> movies = movieService.query().list();
        List<String> types = movies.stream().map(Movie::getType).distinct().toList();
        List<Float> ratings = movies.stream().map(Movie::getRating).distinct().toList();
        return new TypeAvgRating(types, ratings);
    }

    @GetMapping("/region_movie_count")
    public List<RegionMovieCount> getRegionMovieCount(){
        return movieService.getRegionMovieCount();
    }
}
